home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / copsnrob.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  2KB  |  64 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11.  
  12. static int gun_mask[] = {0x7e, 0x7d, 0x7b, 0x77, 0x6f, 0x5f, 0x3f};
  13.  
  14. extern unsigned char *copsnrob_carimage;
  15.  
  16. // The gun control is a 7 position switch. I'm doing the following to
  17. // emulate it:
  18. //
  19. // I read out the current gun position via the sprite image locations,
  20. // and then decrement/increment it if the up/down keys are pressed.
  21.  
  22. READ_HANDLER( copsnrob_gun_position_r )
  23. {
  24.     int keys, current_car_image, current_gun_pos = 0;
  25.  
  26.     // Determine which player we need
  27.     switch (offset)
  28.     {
  29.     default:
  30.     case 0x00:
  31.         current_car_image = copsnrob_carimage[0];
  32.         keys = input_port_4_r(0);
  33.         break;
  34.     case 0x04:
  35.         current_car_image = copsnrob_carimage[1];
  36.         keys = input_port_5_r(0);
  37.         break;
  38.     case 0x08:
  39.         current_car_image = copsnrob_carimage[2];
  40.         keys = input_port_6_r(0);
  41.         break;
  42.     case 0x0c:
  43.         current_car_image = copsnrob_carimage[3];
  44.         keys = input_port_7_r(0);
  45.     }
  46.  
  47.     if (current_car_image < 7)
  48.     {
  49.         current_gun_pos = 6 - current_car_image;
  50.     }
  51.     else if (current_car_image < 14)
  52.     {
  53.         current_gun_pos = 13 - current_car_image;
  54.     }
  55.  
  56.     // Gun up
  57.     if ((keys & 0x01) && (current_gun_pos != 6))  current_gun_pos++;
  58.  
  59.     // Gun down
  60.     if ((keys & 0x02) && (current_gun_pos != 0))  current_gun_pos--;
  61.  
  62.     return (keys & 0x80) | gun_mask[current_gun_pos];
  63. }
  64.